from rest_framework.decorators import action
from rest_framework.viewsets import ModelViewSet
from .models import Skill
from .serializers import SkillSerializer
from rest_framework.response import Response


class SkillViewSet(ModelViewSet):
    serializer_class = SkillSerializer
    queryset = Skill.objects.all()

    @action(methods=["GET"], detail=False)
    def get_radar(self, request):
        queryset = self.get_queryset()

        skill_indicators = []  # 技能图表指示器
        skill_datas = []  # 技能分数

        for query in queryset:
            skill_indicators.append({'text': query.name, "max": 100})
            skill_datas.append(query.score)

        return_data = {
            "title": "个人能力展现",
            "legend": ["编程技能"],
            "indicator": skill_indicators,
            "datas": skill_datas
        }

        return Response(data=return_data)
